package com.jr.controller;

import com.jr.entry.Enterprise;
import com.jr.entry.Posts;
import com.jr.pojo.PageMyPots;
import com.jr.service.EnterpriseService;
import com.jr.service.PostsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/EnterpriceAndPosts/")
public class EnterpriceAndPostsController {
    @Autowired
    private PostsService postsService;

    @Autowired
    Enterprise enterprise;

    @Autowired
    private EnterpriseService enterpriseService;

    /**
     * 在我的职位界面
     * 对该账户所有的职业进行全查
     *
     * @param id
     * @return
     */
    @RequestMapping("show")
    public PageMyPots show(Integer id, String pname, @RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "3") int pageSize) {

        Map<String, Object> params = new HashMap();
        params.put("id", id);
        params.put("pname", pname);
        return postsService.selectAllPosts(params, page, pageSize);
    }

    /**
     * 在我的职位界面
     * 对所有职位进行带条件查询
     */
    @RequestMapping("showAll")
    public PageMyPots showAll(String pname, @RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "3") int pageSize) {
        return postsService.selectAllPosts(pname, page, pageSize);
    }

    /**
     * 对一个职位的信息展示
     * 在单个职务展示界面
     *
     * @param pname
     * @return
     */
    @RequestMapping("showPosts")
    public Posts showPosts(String pname) {
        return postsService.selectPotsByPname(pname);
    }

    /**
     * 在单个职务展示界面
     * 对一个公司的信息查询
     *
     * @param business
     * @return
     */
    @RequestMapping("showEnterprise")
    public Enterprise showEnterprise(String business) {
        enterprise.setBusiness(business);
        return enterpriseService.showEnterprise(enterprise);
    }

    /**
     * 在单个职务展示界面
     * 查看用户是否对该职位进行申请
     *
     * @return
     */
    @RequestMapping("astatus")
    public Boolean astatus(String pid, String phone) {
        Map<String, Object> params = new HashMap();
        params.put("pid", pid);
        params.put("phone", phone);
        return postsService.astatus(params);
    }

    /**
     * 在单个职务展示界面
     * 添加申请关系
     *
     * @return
     */
    @RequestMapping("addastatus")
    public Boolean addastatus(String pid, String phone, Integer uid) {
        Map<String, Object> params = new HashMap();
        params.put("pid", Integer.parseInt(pid));
        params.put("phone", phone);
        params.put("uid", uid);
        return postsService.addastatus(params);
    }

    /**
     * 根据用户电话查用户id
     *
     * @return
     */
    @RequestMapping("selectId")
    public Integer selectId(String phone) {
        return postsService.selectId(phone);
    }


}
